local extension = Package:new("chuanqi")
extension.extensionName = "chuanqi"

Fk:loadTranslationTable{
    ["chuanqi"] = "传奇",
}

local lihaitao = General(extension, "lihaitao", "qun", 4, 4, General.Male)

lihaitao.shield = 0

local taoyong = fk.CreateTriggerSkill {
    name = "taoyong",
    anim_type = "offensive",
    frequency = Skill.Compulsory,
    events = {fk.GameStart},
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self.name, false, true) then

            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        for _, p in ipairs(player.room:getOtherPlayers(player)) do
            if p.gender == 2 then
                p.room:addPlayerMark(p, "@tao", 1)
            end

        end
    end
}



local touxin = fk.CreateActiveSkill {
    name = "touxin",
    anim_type = "offensive",
    card_num = 0,
    min_target_num = 1,
    prompt = function(self)
        return "她怎么会错啊？都是我错了----"
      end,
    can_use = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
    card_filter = function(self, to_select, selected)
        return false
    end,
    target_filter = function(self, to_select, selected)
        local target = Fk:currentRoom():getPlayerById(to_select)
        return to_select ~= Self.id and target:getMark("@tao") == 1
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local removeTouxinNum = #effect.tos

        for _, p in ipairs(effect.tos) do
            local target = room:getPlayerById(p)
            if player.dead or target.dead then
                return
            end
            room:removePlayerMark(target, "@tao", 1)
            if player:isWounded() then
                room:recover({
                    who = player,
                    num = 1,
                    recoverBy = player,
                    skillName = self.name
                })
            end
            player:drawCards(1, self.name)
        end

        local hasTaoNum = 0
        for _, p in ipairs(player.room:getOtherPlayers(player)) do
            if p:getMark("@tao") == 1 then
                hasTaoNum = hasTaoNum + 1
            end
        end

        local room = player.room
        local card_ids = room:getNCards(removeTouxinNum + 1)
        local get, throw = {}, {}
        room:moveCards({
            ids = card_ids,
            toArea = Card.Processing,
            moveReason = fk.ReasonPut
        })
        table.forEach(room.players, function(p)
            room:fillAG(p, card_ids)
        end)
        while true do
            -- local sum = 0
            -- table.forEach(get, function(id)
            --     sum = sum + Fk:getCardById(id).number
            -- end)
            for i = #card_ids, 1, -1 do
                local id = card_ids[i]
                if #get > hasTaoNum then
                    room:takeAG(player, id, room.players)
                    table.insert(throw, id)
                    table.removeOne(card_ids, id)
                end
            end
            if #card_ids == 0 then
                break
            end
            local card_id = room:askForAG(player, card_ids, false, self.name)
            -- if card_id == nil then break end
            room:takeAG(player, card_id, room.players)
            table.insert(get, card_id)
            table.removeOne(card_ids, card_id)
            if #card_ids == 0 then
                break
            end
        end
        table.forEach(room.players, function(p)
            room:closeAG(p)
        end)
        if #get > 0 then
            local dummy = Fk:cloneCard("dilu")
            dummy:addSubcards(get)
            room:obtainCard(player.id, dummy, true, fk.ReasonPrey)
        end
        if #throw > 0 then
            room:moveCards({
                ids = throw,
                toArea = Card.DiscardPile,
                moveReason = fk.ReasonPutIntoDiscardPile
            })
        end

    end
}

local touxin_targetmod = fk.CreateTargetModSkill{
  name = "#touxin_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return player:hasSkill("touxin") and scope == Player.HistoryPhase and to:getMark("@tao") == 0
  end,
  bypass_distances = function(self, player, skill, card, to)
    return player:hasSkill("touxin") and to:getMark("@tao") == 0
  end,
}

touxin:addRelatedSkill(touxin_targetmod)




local ciduo = fk.CreateTriggerSkill {
    name = "ciduo",
    frequency = Skill.Wake,
    events = {fk.EventPhaseStart},
    can_trigger = function(self, event, target, player, data)
        return
            target == player and player:hasSkill(self.name) and player:usedSkillTimes(self.name, Player.HistoryGame) ==
                0 and player.phase == Player.Start
    end,
    can_wake = function(self, event, target, player, data)
        taoNum = 0
        for _, p in ipairs(player.room:getOtherPlayers(player)) do
            if p:getMark("@tao") == 1 then
                taoNum = taoNum + 1
            end
        end

        return taoNum == 0
    end,
    on_use = function(self, event, target, player, data)
        player.gender = 2
        for _, p in ipairs(player.room:getOtherPlayers(player)) do
            if p.gender == 1 then
                p.room:addPlayerMark(p, "@tao", 1)
            end
        end

    end
}
lihaitao:addSkill(taoyong)
lihaitao:addSkill(touxin)
lihaitao:addSkill(ciduo)
Fk:loadTranslationTable{
    ["lihaitao"] = "谋李海涛",
    ["taoyong"] = "涛涌",
    [":taoyong"] = "游戏开始时，你令场上所有女性角色获得“涛”标记。拥有“涛”标记的角色无法对你造成伤害。",
    ["ciduo"] = "雌堕",
    [":ciduo"] = "锁定技，觉醒技，当场上没有角色拥有“涛”标记时，你可以令所有男性角色获得“涛”标记。直到游戏结束，你被视为女性角色。",
    ["touxin"] = "偷心",
    [":touxin"] = "出牌阶段限一次，你可以移去场上任意数量的“涛”标记，并观看牌堆顶X张牌（X为移去“涛”标记的数量+1），然后获得其中Y张牌（Y为场上拥有“涛”标记的其他角色数），本回合你对没有涛标记的角色使用牌无距离次数限制。",

    ["$taoyong1"] = "打个分，看看值不值得我出手。",
    ["$taoyong2"] = "亏妻者百财不入，别对不起妻子。",
    ["$touxin1"] = "真诚才是必杀技。",
    ["$touxin2"] = "他怎么会错啊，都是我的错~~~",
    ["$ciduo1"] = "呵，男人~~",
    ["$ciduo2"] = "别说了，男人没一个好东西！",
    ["~lihaitao"] = "卧槽，为何我不能C啊~~~~~~",

    ["@tao"] = "涛"
}





local silingshushi = General(extension, "silingshushi", "qun", 4, 4, General.Male)

lihaitao.shield = 0

local zhaohuanshu = fk.CreateActiveSkill {
    name = "zhaohuanshu",
    anim_type = "offensive",
    prompt = function(self)
        return "是否发动召唤术"
      end,
    can_use = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) < 4
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local markNum=player:getMark("@guaiwu")
        
        local mosterCardId=room:getNCards(1,"bottom")[1]
        local check = math.random(1, 6)
        local mosterCard=Fk:getCardById(mosterCardId)
        if check> player.hp then
            player.room:addPlayerMark(player, "@guaiwu", 1)
            room:moveCardTo(mosterCard, Card.PlayerHand, player, fk.ReasonDraw, self.name, nil, false)
        else
            player.room:addPlayerMark(player, "@eyun", 1)
            room:moveCardTo(mosterCard, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name)
            
        end
    end
}
local guaiwugongji = fk.CreateActiveSkill {
    name = "guaiwugongji",
    anim_type = "offensive",
    target_num = 1,
    prompt = function(self)
        return "弃置一个怪物标记并选择自己增加1点护甲或其他角色对其造成1点伤害"
      end,
    can_use = function(self, player)
        local markNum=player:getMark("@guaiwu")

        return player:hasSkill(self.name) and (markNum>0)
    end,

    target_filter = function(self, to_select, selected)
        return true
      end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local target = room:getPlayerById(effect.tos[1])
        room:removePlayerMark(player, "@guaiwu", 1)
        if player==target then
            room:changeShield(player, 1)
            

        else
            room:damage {
                from = player, to = target,
                damage = 1, skillName = self.name, damageType = fk.NormalDamage,
              }
        end

    end
    }

local huituzhuansheng = fk.CreateActiveSkill {
    name = "huituzhuansheng",
    anim_type = "offensive",
    prompt = function(self)
        return "是否发动秽土转生技能"
      end,
    can_use = function(self, player)
        local choiceList={}
        for _, p in ipairs(Fk:currentRoom().players) do
            if p.dead then
                table.insert(choiceList,p.general)
            end
        end

        return (player:usedSkillTimes(self.name, Player.HistoryGame) == 0) and (#choiceList > 0)
    end,
    card_filter = function(self, to_select, selected)
        return false
    end,
    target_filter = function(self, to_select, selected)

        local target = Fk:currentRoom():getPlayerById(to_select)
        return false
    end,
    on_use = function(self, room, effect)

        local choiceList={}
        for _, p in ipairs(Fk:currentRoom().players) do
            if p.dead then
                table.insert(choiceList,p.general)
            end
        end
        local player = room:getPlayerById(effect.from)


        local choice = room:askForChoice(player, choiceList, self.name,"请选择秽土转生的玩家")

        
        local check = math.random(1, 4)
        player.room:addPlayerMark(player, "@eyun", check)
        for _, p in ipairs(Fk:currentRoom().players) do
            if p.general==choice then
                room:revivePlayer(p)
                room:loseHp(p,p.maxHp-check, self.name)
                p:drawCards(check, self.name)
            end
        end
    end
}
local shenyuandeningshi = fk.CreateTriggerSkill {
    name = "shenyuandeningshi",
    anim_type = "offensive",
    frequency = Skill.Compulsory,
    events = {fk.EventPhaseStart},
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self.name, false, true) and player.phase == Player.Finish then

            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local markNum=player:getMark("@eyun")
        local check=math.random(1,7)
        if check>markNum then
            player.room:drawCards(player,1, self.name)

        else
            if markNum==1 then
                local cards=player:getCardIds()
                local dropCard=table.random(cards,1)
                player.room:throwCard(dropCard, self.name, player, player)

            elseif markNum==2 then
                player:turnOver()
            elseif markNum==3 then
                player.room:loseHp(player,1,self.name)
            elseif markNum==4 then
                player.room:loseHp(player,2,self.name)
            elseif markNum==5 then
                player.room:loseHp(player,3,self.name)
            elseif markNum>=6 then
                player.room:loseHp(player,4,self.name)
                
            end
        end

    end
}
silingshushi:addSkill(zhaohuanshu)
silingshushi:addSkill(huituzhuansheng)
silingshushi:addSkill(shenyuandeningshi)
silingshushi:addSkill(guaiwugongji)
Fk:loadTranslationTable{
    ["silingshushi"] = "死灵术士",
    ["huituzhuansheng"] = "秽土转生",
    [":huituzhuansheng"] = "限定技，进行一次1d3检定并复活一名玩家，你获得X个厄运标记 该玩家恢复X点体力 摸X张牌（X为检定结果）",
    ["shenyuandeningshi"] = "深渊的凝视",
    [":shenyuandeningshi"] = "锁定技，在你的结束阶段时，进行一次1d6的凝视检定，若点数大于“厄运”标记数，则你摸一张牌，若小于等于标记数，则根据“厄运”标记数量触发以下事件：<br>"
    .."1. <font  color=\"red\"  size=\"4\">《来自古神的警告》</font>随机弃置你一张牌<br>"
    .."2. <font  color=\"red\"  size=\"4\">《疯言疯语》</font>你翻面<br>"
    .."3. <font  color=\"red\"  size=\"4\">《虚空捕食者的偷袭》</font>你受到一点伤害<br>"
    .."4. <font  color=\"red\"  size=\"4\">《被腐化的身体》</font>随机废除你的一个装备区域<br>"
    .."5. <font  color=\"red\"  size=\"4\">《旧日支配者的低语》</font>全场所有人轮流进行1d6检定，点数大于体力值则受到2点伤害。<br>"
    .."6. <font  color=\"red\"  size=\"4\">《旧日支配者的降临》</font>全场所有人轮流进行一次判定，不为桃或桃园结义则死亡。<br>(目前4-6为简易版，分别受到234点伤害)",
    ["zhaohuanshu"] = "召唤术",
    [":zhaohuanshu"] = "出牌阶段限3次，展示牌堆底的一张牌并进行1d6的召唤检定，点数大于你的体力值则召唤成功，获得该牌并增加一点“怪物”标记，点数小于你的体力值则召唤失败，弃置该牌并获得一个“厄运”标记。",
    ["guaiwugongji"] = "怪物攻击",
    [":guaiwugongji"] = "你可以弃置一个怪物标记后选择自己增加1点护甲或其他角色对其造成1点伤害",


    ["@guaiwu"] = "怪物",
    ["@eyun"] = "厄运"

    
}



return extension
